package com.ax.center.controller;

import com.ax.center.annotation.Logging;
import com.ax.center.dto.ApiResponse;
import com.ax.center.entity.Role;
import com.ax.center.entity.UserRole;
import com.ax.center.service.UserRoleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author zy
 * @date 2023/7/6 16:09
 */

@RestController
@RequestMapping(value = "userRoleController")
@Api(tags = "用户角色服务")
@CrossOrigin(origins = "http://localhost:5173")
public class UserRoleController {
    @Autowired
    private UserRoleService userRoleService;



    @PostMapping("/无效的请求")
    public void test(@RequestBody UserRole userRole){
        return;
    }


    @Logging(description = "查询用户的所有角色")
    @GetMapping(value = "/queryRoleName/{userId}")
    @ApiOperation("查询用户的所有角色")
    public ApiResponse queryRoleName(@PathVariable("userId")Long userId){
        List<Role> roles = userRoleService.queryRoleNameByUserId(userId);
        return  ApiResponse.ok(roles);
    }

    @Logging(description = "向用户新增角色")
    @GetMapping(value = "/insertRole/{userId}/{roleId}")
    @ApiOperation("向用户新增角色")
    public ApiResponse insertRole(@PathVariable("userId")Long userId,@PathVariable("roleId")Long roleId){
        return userRoleService.insertRole(userId,roleId);
    }

    @Logging(description = "删除用户所属的角色")
    @GetMapping(value = "/deleteRole/{roleId}")
    @ApiOperation( "删除用户所属的角色")
    public ApiResponse deleteRole(@PathVariable("roleId")Long roleId){
        return userRoleService.deleteOneByRoleId(roleId);
    }

    @Logging(description = "修改用户所属的角色")
    @GetMapping(value = "/updateRole/{staffId}/{roleId}")
    @ApiOperation( "修改用户所属的角色")
    public ApiResponse updateRole(@PathVariable("staffId")Long staffId,@PathVariable("roleId")Long roleId){
     return userRoleService.updateRole(staffId,roleId);
    }



}
